home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
DELPHI32
/
SYS_TOOL
/
MULTI020
/
MPFILE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-09-07
|
2KB
|
91 lines
unit mpfile;
{ File in- and output clients for MPipes }
interface
uses multi, mpipes;
procedure AttachFileInTask(const fname : string; m : pPipe);
{ Start client which feeds data from the file into the pipe. }
procedure AttachFileOutTask(const fname : string; m : pPipe);
{ Start client which feeds data from the pipe to the file. }
implementation
type
pipeinforec = record
p : pPipe;
f : file;
end;
procedure FileInTask(var m); far;
var
pipeinfo : pipeinforec absolute m;
w : word;
fbuf : array[1..1024] of char;
begin
t^.hasexit := true;
pipeinfo.p^.NewInputTask;
repeat
blockread(pipeinfo.f,fbuf,1024,w);
if pipeinfo.p^.PutBin(fbuf,w) then break;
if w < 1024 then break;
until false;
close(pipeinfo.f);
pipeinfo.p^.NoMoreInput;
freemem(@m,sizeof(pipeinforec))
end;
procedure FileOutTask(var m); far;
var
pipeinfo : pipeinforec absolute m;
w : word;
fbuf : array[1..1024] of char;
begin
t^.hasexit := true;
pipeinfo.p^.NewOutputTask;
w := 0;
repeat
fbuf[w] := pipeinfo.p^.Get;
if t^.Poisoned then break;
inc(w);
if w = 1024 then begin
blockwrite(pipeinfo.f,fbuf,1024,w);
if w < 1024 then break;
w := 0
end;
until false;
blockwrite(pipeinfo.f,fbuf,w,w);
close(pipeinfo.f);
pipeinfo.p^.NoMoreOutput;
freemem(@m,sizeof(pipeinforec))
end;
procedure AttachFileInTask(const fname : string; m : pPipe);
var p : ^pipeinforec;
begin
new(p);
p^.p := m;
assign(p^.f,fname); {$I-} reset(p^.f,1); {$I+}
if ioresult = 0 then begin
Fork(FileInTask,3*1024,p^
{$IFDEF DEBUG} ,'FileIn '+fname {$ENDIF});
end else
dispose(p)
end;
procedure AttachFileOutTask(const fname : string; m : pPipe);
var p : ^pipeinforec;
begin
new(p);
p^.p := m;
assign(p^.f,fname); {$I-} rewrite(p^.f,1); {$I+}
if ioresult = 0 then begin
Fork(FileInTask,3*1024,p^
{$IFDEF DEBUG} ,'FileOut '+fname {$ENDIF});
end else
dispose(p)
end;
end.